/**
 * 
 */
package com.seraph.zys.web.system;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.seraph.bi.suite.support.core.resources.ConvertDataDeclareCell;
import com.seraph.bi.suite.support.core.resources.LocalResourcesDeclareProxy;
import com.seraph.bi.suite.support.core.resources.LocalResourcesInitial;

/**
 * 类说明: 刷新系统缓存<br>
 * 创建时间: 2008-9-1 下午06:53:23<br>
 * 
 * @author 刘岩松<br>
 * @email: seraph115@gmail.com<br>
 */
@Controller
@RequestMapping("/cacheRefresh.do")
public class CacheRefreshController extends AbstractController {

	@Autowired
	private LocalResourcesInitial localResourcesInitial;

	public void setLocalResourcesInitial(
			LocalResourcesInitial localResourcesInitial) {
		this.localResourcesInitial = localResourcesInitial;
	}

	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		LocalResourcesDeclareProxy proxy = localResourcesInitial.getLocalResourcesDeclareProxy();
		List<ConvertDataDeclareCell> cells = proxy.getConvertDataDeclareCells();
		map.put("cells", cells);
		
		String refresh = request.getParameter("refresh");
		String[] cellArray = request.getParameterValues("cellList");
	
		if ("true".equals(refresh)) {
			if (!ArrayUtils.isEmpty(cellArray)) {
				List<String> cellList = Arrays.asList(cellArray);
				localResourcesInitial.rebuild(cellList);
				map.put("message", "缓存刷新成功！");
			} else {
				map.put("warn", "请选择需要刷新的缓存！");
			}
		}
		
		return new ModelAndView("/platform/system/cacheRefresh", map);
	}

}

